# -*- coding: utf-8 -*-
from django import forms
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _, ugettext as __
from app2.models import Category,Entry,Comment

class CategoryForm(forms.ModelForm):  
    def cleaned_data(self):
        memcache.delete("key_all_categories_app2")
        return self.cleaned_data
    
    class Meta:
        exclude = ['entrycount','post_keys']
        model = Category

class EntryForm(forms.ModelForm):
    title = forms.CharField(required = True,widget=forms.widgets.Input(attrs={'style':"width:500px;padding:4px;"}), max_length=50, label=_(u'Title'))
    content = forms.CharField(required = True,widget=forms.widgets.Textarea(attrs={'style':"width:600px;height:400px;",'rows': 22,'cols': 75,'class':'tinymce'}), max_length=10000, label=_(u'Content'))
            
    class Meta:
        exclude = ['category','author','prev_key','next_key','pub_time','edit_time','commentcount','comment_keys','author_profile']
        model = Entry

class CommentForm(forms.ModelForm):
    message = forms.CharField(required = True,widget=forms.widgets.Textarea(attrs={'style':"width:500px;height:100px;"}), max_length=300, label=_(u'Message'),help_text=_(u'Max length 300s'))
    
    def clean(self):
        message = self.cleaned_data.get('message','')
        if message:
            message = message.replace("<script","< script")
            message = message.replace("</script>","< /script>")
            message = message.replace("\n","<br/>")
        self.cleaned_data['message'] = message
        return self.cleaned_data
        
    class Meta:
        exclude = ['entry','date','author_profile']
        model = Comment
